package com.nanbei.cas;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicStampedReference;
import java.util.concurrent.atomic.LongAccumulator;

/**
 * @ClassDescription: 带版本号的CAS
 * @JdkVersion: 1.8
 * @Author: libs
 * @Created: 2024/10/9 10:55
 */
public class AtomicStampedReferenceDemo {
    public static void main(String[] args) {
        AtomicStampedReference<Integer> integerAtomicStampedReference = new AtomicStampedReference<Integer>(0,0);
        /**
         *
         * expectedReference – 引用的预期值
         * newReference – 引用的新值
         * expectedStamp – 标记的预期值
         * newStamp – 标记的新值
         *
         */
        integerAtomicStampedReference.compareAndSet(0,100,
                0,integerAtomicStampedReference.getStamp()+1);
        System.out.println(integerAtomicStampedReference.getReference());

        // getStamp() 返回当前原子类的版本号
        System.out.println(integerAtomicStampedReference.getStamp());


    }
}
